<template>
	<view class="content">
		<!-- 商家 -->
		<view class="box" v-if="user_type">
			<view class="shop-img" @click="upLoadImg">
				<image v-if="storeMsg.shavatar == 0" src="/static/imgs/comment-icon2.png" mode="aspectFill"></image>
				<image v-else :src="storeMsg.shavatar" mode="aspectFill"></image>
				<text>点击更改店铺头像</text>
			</view>
			<view class="shop-detils">
				<view class="name" @click="navTo('/pages/myStore/setting/shopName')">
					<text>店铺名称</text>
					<text>{{storeMsg.shname}}<text class="iconfont">&#xe600;</text></text>
				</view>
				<view class="name" @click="navTo('/pages/myStore/setting/shopAddress')">
					<text>经营地址</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
				<view class="name" @click="navTo('/pages/myStore/setting/shopDeclaration')">
					<text>店铺宣言</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
				<view class="name" @click="navTo('/pages/myStore/setting/manageTimes')">
					<text>营业时间</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
				<view class="name" @click="navTo('/pages/myStore/setting/shopImg')">
					<text>店铺环境</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
				<view class="name" @click="navTo('/pages/myStore/setting/shopAttest')">
					<text>店铺认证</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
				<view class="name" @click="navTo('/pages/myStore/setting/shopPhone')">
					<text>联系方式</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
			</view>
		</view>
		<!-- 个人 -->
		<view class="box" v-else>
			<view class="shop-img" @click="upLoadImg">
				<image :src="storeMsg.shavatar"></image>
				<text>点击更改店铺头像</text>
			</view>
			<view class="shop-detils">
				<view class="name" @click="navTo('/pages/myStore/setting/shopName')">
					<text>店铺名称</text>
					<text>{{storeMsg.shname}}<text class="iconfont">&#xe600;</text></text>
				</view>
				<view class="name" @click="navTo('/pages/myStore/setting/shopDeclaration')">
					<text>店铺宣言</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
				
				<view class="name" @click="navTo('/pages/myStore/setting/shopPhone')">
					<text>联系方式</text>
					<text><text class="iconfont">&#xe600;</text></text>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex";
	var _self = this;
	export default {
		data() {
			return {
				user_type: true, // true为企业店铺，false为个人店铺
				storeMsg: {},
				shid: '', // 店铺ID
			}
		},
		onLoad() {
			this.shid = uni.getStorageSync('lph-user-info').shid;
			this.getShopM();
			this.knowUserType();
			// 把店铺名存储到vuex中
		},
		onShow() {
			this.getShopM();
			// this.get();
		},
		computed:{
			...mapState(['storeInfo'])
		},
		methods: {
			...mapMutations(['changeStoreInfo','changeShName', 'setShDetails', 'changeShDetails']),
			knowUserType() { // 判断用户类型
				let a = uni.getStorageSync('lph-user-info');
				if(a.user_type == 3){
					this.user_type = true;
					return
				}
				this.user_type = false;
			},
			
			
			async getShopM() {
				let a = await this.$http.getShopMessage({shid:this.shid});
				
				this.storeMsg = a.data;
				uni.setStorageSync('lph-storeInfo',a.data);
			},
			get() {
				this.storeMsg = uni.getStorageSync('lph-storeInfo');
			},

			//上传店铺头像
			upLoadImg() {
				uni.chooseImage({
					count: 1, //限制1张图片
					sizeType: ['compressed'], //压缩图
					sourceType: ['album'], //从相册选
					success: (res) => {
						this.shopImg = res.tempFilePaths[0]
						uni.uploadFile({ //图片上传
							url: this.$common.baseUrl.setUploadImg, 
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {},
							success: (res) => {
								let res1 = JSON.parse(res.data)
								let c =  this.$http.setShopPortrait({ // 更换头像
									shavatar: res1.data.file,
								});
								this.storeMsg.shavatar = res1.data.file;
								uni.setStorageSync('lph-storeInfo', res1.data.file)
								// let info = {
								// 	name: 'shavatar',
								// 	msg: res1.data.file
								// }
								// this.changeStoreInfo(info);
							},
							fail: (e) => {

							}
						});
					}
				});
			},
			navTo(url) {
				uni.navigateTo({url})
			},



		
		}
	}
</script>

<style lang="scss">
	@import 'static/css/shopDetils.scss'
</style>
